package tp.pr5.instructions;

import tp.pr5.NavigationModule;
import tp.pr5.RobotEngine;
import tp.pr5.instructions.exceptions.InstructionExecutionException;
import tp.pr5.instructions.exceptions.WrongInstructionFormatException;
import tp.pr5.items.ItemContainer;

public class UndoInstruction extends UndoAble{
	RobotEngine rbt;
	@Override
	public Instruction parse(String cad) throws WrongInstructionFormatException {
		if(cad.equalsIgnoreCase("UNDO") || cad.equalsIgnoreCase("DESHACER")){//si la acciÃ³n introducida es DESHACER
			return new UndoInstruction();
		}else{
			throw new WrongInstructionFormatException();
		}
	}

	@Override
	public String getHelp() {
		return "     UNDO|DESHACER";
	}

	@Override
	public void configureContext(RobotEngine engine,
			NavigationModule navigation, ItemContainer robotContainer) {
		this.rbt = engine;
		
	}

	@Override
	public void execute() throws InstructionExecutionException {
		if(rbt.getLastInstruction().isUndoAble()){
			rbt.getLastInstruction().undo();
		}
	}

	@Override
	public boolean isUndoAble() {

		return false;
	}
	/**
	 * revets the las instruction
	 */
	
}
